// com.example.service.impl.PlanServiceImpl.java
package com.example.service.impl;

import com.example.dao.PlanDao;
import com.example.entity.Plan;
import com.example.service.PlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class PlanServiceImpl implements PlanService {

    @Autowired
    private PlanDao planDao;

    @Override
    public List<Plan> getAllPlans() {
        return planDao.findAll();
    }

    @Override
    public Plan getPlanById(Integer planid) {
        return planDao.findById(planid);
    }

    @Override
    public boolean addPlan(Plan plan) {
        try {
            return planDao.insert(plan) > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean updatePlan(Plan plan) {
        try {
            return planDao.update(plan) > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean deletePlan(Integer planid) {
        try {
            return planDao.delete(planid) > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}